package com.yxx.business.service.impl;

import java.util.List;

import com.yxx.common.annotation.DataScope;
import com.yxx.common.utils.DateUtils;
import com.yxx.common.core.domain.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import com.yxx.common.core.service.impl.ServiceImplPlus;
import com.yxx.business.mapper.TbEquipmentInfoMapper;
import com.yxx.business.entity.TbEquipmentInfoDo;
import com.yxx.business.entity.TbEquipmentInfoVo;
import com.yxx.business.entity.TbEquipmentInfoQueryDto;
import com.yxx.business.entity.TbEquipmentInfoEditDto;
import com.yxx.business.service.ITbEquipmentInfoService;

/**
 * 设备信息Service业务层处理
 *
 * @author yxx
 * @date 2025-08-11
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy, @Autowired})
public class TbEquipmentInfoServiceImpl extends ServiceImplPlus<TbEquipmentInfoMapper, TbEquipmentInfoDo> implements ITbEquipmentInfoService {

    private final ITbEquipmentInfoService self;

    private final TbEquipmentInfoMapper tbEquipmentInfoMapper;

    /**
     * 查询设备信息分页结果
     *
     * @param tbEquipmentInfoQueryDto 设备信息查询实体
     * @return 设备信息分页
     */
    @Override
    public PageResult<TbEquipmentInfoVo> selectTbEquipmentInfoVoPage(TbEquipmentInfoQueryDto tbEquipmentInfoQueryDto) {
        startPage();
        PageResult<TbEquipmentInfoVo> page
                = super.getMyBatisPageResult(self.selectTbEquipmentInfoDoList(tbEquipmentInfoQueryDto), TbEquipmentInfoVo.class);
        clearPage();
        return page;
    }

    /**
     * 查询设备信息Vo列表
     *
     * @param tbEquipmentInfoQueryDto 设备信息查询实体
     * @return 设备信息集合
     */
    @Override
    public List<TbEquipmentInfoVo> selectTbEquipmentInfoVoList(TbEquipmentInfoQueryDto tbEquipmentInfoQueryDto) {
        return super.convertList(tbEquipmentInfoMapper.selectTbEquipmentInfoList(tbEquipmentInfoQueryDto), TbEquipmentInfoVo.class);
    }

    /**
     * 查询设备信息Do列表
     *
     * @param tbEquipmentInfoQueryDto 设备信息查询实体
     * @return 设备信息集合
     */
    @Override
    public List<TbEquipmentInfoDo> selectTbEquipmentInfoDoList(TbEquipmentInfoQueryDto tbEquipmentInfoQueryDto) {
        return tbEquipmentInfoMapper.selectTbEquipmentInfoList(tbEquipmentInfoQueryDto);
    }

    /**
     * 查询单个设备信息
     *
     * @param equipmentInfoId 设备信息主键
     * @return 设备信息单个
     */
    @Override
    public TbEquipmentInfoVo selectTbEquipmentInfoVoByEquipmentInfoId(Long equipmentInfoId) {
        return super.convertBean(tbEquipmentInfoMapper.selectTbEquipmentInfoByEquipmentInfoId(equipmentInfoId), TbEquipmentInfoVo.class);
    }

    /**
     * 新增设备信息
     *
     * @param tbEquipmentInfoQueryDto 设备信息编辑实体
     * @return 结果
     */
    @Override
    public int insertTbEquipmentInfo(TbEquipmentInfoEditDto tbEquipmentInfoQueryDto) {
        tbEquipmentInfoQueryDto.setCreateBy(getUserNameOrNotLogged());
        tbEquipmentInfoQueryDto.setCreateTime(DateUtils.getNowDate());
        return tbEquipmentInfoMapper.insertTbEquipmentInfo(super.convertT(tbEquipmentInfoQueryDto).setCreateById(getUserIdOrNotLogged()));
    }

    /**
     * 修改设备信息
     *
     * @param equipmentInfoId 设备信息主键
     * @param tbEquipmentInfoQueryDto 设备信息编辑实体
     * @return 结果
     */
    @Override
    public int updateTbEquipmentInfo(Long equipmentInfoId, TbEquipmentInfoEditDto tbEquipmentInfoQueryDto) {
        tbEquipmentInfoQueryDto.setUpdateBy(getUserNameOrNotLogged());
        tbEquipmentInfoQueryDto.setUpdateTime(DateUtils.getNowDate());
        return tbEquipmentInfoMapper.updateTbEquipmentInfo(super.convertT(tbEquipmentInfoQueryDto).setEquipmentInfoId(equipmentInfoId));
    }

    /**
     * 批量删除设备信息
     *
     * @param equipmentInfoIds 需要删除的设备信息主键集合
     * @return 结果
     */
    @Override
    public int deleteTbEquipmentInfoByEquipmentInfoIds(List<Long> equipmentInfoIds) {
        return tbEquipmentInfoMapper.deleteTbEquipmentInfoByEquipmentInfoIds(equipmentInfoIds);
    }

    /**
     * 删除单个设备信息信息
     *
     * @param equipmentInfoId 设备信息主键
     * @return 结果
     */
    @Override
    public int deleteTbEquipmentInfoByEquipmentInfoId(Long equipmentInfoId) {
        return tbEquipmentInfoMapper.deleteTbEquipmentInfoByEquipmentInfoId(equipmentInfoId);
    }

    @Override
    public Boolean importEquipmentList(List<TbEquipmentInfoEditDto> list) {
        list.forEach(this::insertTbEquipmentInfo);
        return true;
    }
}
